<?php
/**
 * This file is part of manage.
 * Author: tangzhou
 * Date: 2016/5/17
 * Time: 14:09
 * File: Vcc601705260Controller.php
 */

namespace Ivr\HttpBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
 * Class Vcc601705260Controller
 * @package Ivr\HttpBundle\Controller
 */
class Vcc6017052601Controller extends Controller
{
    /**
     * 1销售，2服务
     * @var array
     */
    public $key = array(
        'code' => array(
            '1' => array(1003, 1004, 1005, 1006, 1007),
            '2' => array(1008, 1009, 1010, 1011, 1012),
        ),
        'data' => array(
            array(
                '0451', '0452', '0459', '0458', '0453', '0454', '0455', '0457', '0456',
                '024', '0411', '0412', '0413', '0414', '0415', '0416', '0417', '0418', '0419', '0410',
                '0471', '0472', '0473', '0476', '0479', '0470', '0475', '0477', '0482',
                '0431', '0423', '0434', '0437', '0435', '0439', '0436', '0433', '0440',
                '0351', '0352', '0353', '0355', '0349', '0354', '0358', '0357', '0359',
            ),
            array(
                '010',
                '022',
                '0311', '0310', '0319', '0312', '0313', '0314', '0315', '0335', '0317', '0316', '0318',
                '0371', '0378', '0379', '0373', '0393', '0370', '0377', '0394', '0396', '0375', '0372',
            ),
            array(
                '0531', '0532', '0533', '0536', '0535', '0631', '0538', '0537', '0633', '0534', '0530',
                '025', '0516', '0518', '0517', '0527', '0515', '0514', '0513', '0511', '0519', '0510', '0512', '0520',
                '021',
                '0551', '0554', '0552', '0555', '0556', '0559', '0550', '0557', '0565', '0563',
                '027', '0714', '0710', '0719', '0717', '0714', '0712', '0713', '0718', '0716',
                '0571', '0574', '0573', '0572', '0575', '0579', '0570', '0580', '0577', '0576',
            ),
            array(
                '0791', '0798', '0790', '0792', '0701', '0793', '0795', '0794', '0796', '0797',
                '0591', '0592', '0598', '0594', '0595', '0596', '0599', '0593', '0597', '0668',
                '0731', '0733', '0732', '0734', '0730', '0736', '0735', '0737', '0746', '0745', '0744',
                '020', '0755', '0756', '0754', '0751', '0752', '0769', '0760', '0757', '0759', '0758',
                '0771', '0772', '0773', '0774', '0779', '0777','0776', '0770',
                '0898', '0899', '0890',
                '0871', '0870', '0874', '0877', '0879', '0888', '0873', '0878',
                '0851', '0852', '0853', '0858',

            ),
            array(
                '028', '0812', '0838', '0816', '0813', '0832', '0833', '0830', '0831',
                '023',
                '0891', '0892', '08018', '08059', '0897',
                '029', '0919', '0917', '0913', '0914', '0916', '0912',
                '0991', '0990', '0995', '0998', '0908', '0996','0952', '0951',
                '0931', '0935', '0938', '0933', '0937', '0937',
                '0971', '0972', '0979', '0975',
            ),
        ),
    );

    /**
     * @param Request $request
     * @return JsonResponse
     */
    public function indexAction(Request $request)
    {
        $phone = $request->get('phone', '');
        $key = $request->get('key', '');   //1是销售   2是服务
        if (empty($phone) || empty($key)) {
            $this->get("logger")->error(sprintf("phone或key为空,phone【%s】,key【%s】", $phone, $key));

            return new JsonResponse(array('result' => 'failure'));
        }
        if ($key != 1 && $key != 2) {
            return new JsonResponse(array('result' => 'failure'));
        }
        //获取归属地
        $res = $this->container->get("icsoc_data.model.location")->getNumberloc($phone);

        if ($res['code'] != 200 || empty($res['data']['code'])) {
            return new JsonResponse(array('result' => 'failure'));
        }
        $queueId = '';
        $haveing = false;
        foreach ($this->key['data'] as $k => $val) {
            if (in_array($res['data']['code'], $val)) {
                $queueId = $this->key['code'][$key][$k];
                $haveing = true;
                break;
            }
        }
        if ($haveing == false) {
            $this->get("logger")->error(sprintf("不包含该区号【%s】,phone【%s】,key【%s】", $res['data']['code'], $phone, $key));

            return new JsonResponse(array('result' => 'failure'));
        }

        return new JsonResponse(array(
            'result' => 'success',
            'data' => array(
                'tran_que_id' => $queueId,
            ),
        ));
    }
}